const Router = require('koa-router');
const router = new Router();
const {db, QueryTypes, } = require('../../models/db')
const tools = require("../../tools/tool");


// formcust d保存
router.post('/design/saveFormCust', async ctx => {
    if(ctx.user.username !== 'admin') {
        return  ctx.err('没有设计权限')
    }
    let data = ctx.request.body.data
    let id = tools.xe.toNumber(data.id)
    data.width = data.width === '' ? 0 : data.width
    data.height = data.height === '' ? 0 : data.height
    data.hideFooter = data.hideFooter ? 1 : 0
    data.hidePage = data.hidePage ? 1 : 0
    data.hideCheckbox = data.hideCheckbox ? 1 : 0

    if(id) {
        await db.models['formCustV5'].update(data, {
            where: {
                id
            }
        })
        return ctx.suc('保存成功', data)
    }
    else {
        delete data.id
        let ret = await db.models['formCustV5'].create(data)
        return ctx.suc('保存成功', ret)
    }
})









module.exports = router;
